package com.yhf.controller;

import com.yhf.model.Branch;
import com.yhf.model.Stage;
import com.yhf.service.BranchService;
import com.yhf.utils.PageResult;
import com.yhf.utils.QueryPageBean;
import com.yhf.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("branch")
public class BranchController {
    @Autowired
    BranchService branchService;

    /**
     * 根据页码查询分页信息
     * @param queryPageBean 分页信息
     * @return PageResult
     */
    @PostMapping("all")
    public PageResult getAll(@RequestBody QueryPageBean queryPageBean){
        return branchService.pageList(queryPageBean);
    }

    /**
     * 根据branch实体添加项目阶段
     * @param branch 项目阶段实体
     * @return Result
     */
    @PostMapping("add")
    public Result add(@RequestBody Branch branch){
        return branchService.add(branch);
    }
    /**
     * 根据bid查询branch
     * @param bid 阶段id
     * @return Result
     */
    @GetMapping("onestage")
    public Result findOne(String bid){
        return branchService.findStageById(bid);
    }
    /**
     *根据branch实体修改含id
     * @param branch 封装信息的实体
     * @return Result
     */
    @PostMapping("edit")
    public Result edit(@RequestBody Branch branch){
        return branchService.editByStage(branch);
    }
    /**
     * 根据bid将开发商部门状态改成0
     * @param bid 部门id
     * @return Result
     */
    @GetMapping("delete")
    public Result delete(String bid){
        return branchService.deleteBySid(bid);
    }

    /**
     *根据bid查询branch包含project的信息
     * @param map 封装阶段id
     * @return Result
     */
    @PostMapping("findSP")
    public Result findStageP(@RequestBody Map<String, String> map){
        return branchService.findSp(map.get("bid"));
    }


}
